package com;


import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ClipData;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.baselibrary.Constants;
import com.baselibrary.MessageBus;
import com.baselibrary.activity.BaseActivity;
import com.baselibrary.bean.CreateOrderBean;
import com.baselibrary.bean.ReceiveAddressBean;
import com.baselibrary.bean.ShareInfoDataBean;
import com.baselibrary.bean.SharePosterBean;
import com.baselibrary.manager.LoadingManager;
import com.baselibrary.permission.PermissionCollection;
import com.baselibrary.permission.PermissionsUtils;
import com.baselibrary.permission.callback.PermissionsCall;
import com.baselibrary.router.ActivityRouter;
import com.baselibrary.utils.CommonUtil;
import com.baselibrary.utils.DoubleClickHelper;
import com.baselibrary.utils.GsonUtils;
import com.baselibrary.utils.KeyBoardUtils;
import com.baselibrary.utils.SpUtils;
import com.baselibrary.utils.StatusBarUtil;
import com.baselibrary.view.share.SharePopupWindow;
import com.github.lzyzsd.jsbridge.BridgeWebView;
import com.github.lzyzsd.jsbridge.BridgeWebViewClient;
import com.github.lzyzsd.jsbridge.CallBackFunction;
import com.hot.BridgeConstant;
import com.hot.IPJsDispatchCallBack;
import com.hot.JsDispatchCallBack;
import com.jsbridge.R;
import com.okhttp.SendRequest;
import com.okhttp.callbacks.GenericsCallback;
import com.okhttp.sample_okhttp.JsonGenericsSerializator;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import okhttp3.Call;

/**
 * 关忆北丶
 * web公共界面
 */
@Route(path = ActivityRouter.ACTIVITY.ACTIVE_H5_WEB_VIEW)
public class H5WebActivity extends BaseActivity implements JsDispatchCallBack {


    private RelativeLayout mRlWebSignTitle;
    private ImageView mIvWebSignBack;
    private TextView mTvWebSignTitle, mTvWebSignSend;
    private ProgressBar mPbWebSignProgress;
    private BridgeWebView mBridgeWebSign;
    private BridgeWebViewUtils mBridgeUtils;
    private SmartRefreshLayout spRefresh;
    private String mLoadUrl;
    private boolean isJumpMain;
    private boolean isShowSharePop = false;//是否显示 分享弹窗

    //是否禁用侧滑返回 true：禁用，无法侧滑关闭当前页面
    private boolean isBanBackKey = false;
    /**
     * 富文本内容
     */
    private String mContent;
    private IPJsDispatchCallBack mIpJsDispatchCallBack;
    private boolean isRightButton;
    private CreateOrderBean orderBean;
    private ValueCallback<Uri> mUM;
    private ValueCallback<Uri[]> mUMA;
    private String mCM;
    private final static int FCR = 1;

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            //true：禁用，无法侧滑关闭当前页面
            if (isBanBackKey) return true;
            handleBack();
        }
        return false;
//        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_sign_h5;
    }

    @Override
    protected void init() {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        initView();
        initData();
        initListener();
    }

    private void initData() {
        if (getIntent() != null && getIntent().getExtras() != null) {
            Bundle bundle = getIntent().getExtras();
            mLoadUrl = bundle.getString("url");
            if (!TextUtils.isEmpty(mLoadUrl) && mLoadUrl.endsWith("#hiddenTitle")) {
                mRlWebSignTitle.setVisibility(View.GONE);
                StatusBarUtil.setTranslucentStatus(this);
            }
            if (bundle.containsKey("content")) {
                mContent = bundle.getString("content");
            }
            isRightButton = bundle.getBoolean("isRightButton", false);
            mTvWebSignSend.setVisibility(isRightButton ? View.VISIBLE : View.GONE);
            isJumpMain = bundle.getBoolean("isJumpMain");
            if (bundle.containsKey("isShowSharePop")) {
                isShowSharePop = bundle.getBoolean("isShowSharePop");
            }
        }
        //处理键盘弹起，输入框盖住
        if (mRlWebSignTitle.getVisibility() == View.GONE) {//标题栏隐藏时
            View view = findViewById(R.id.view);
            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
            KeyBoardUtils.setListener(this, new KeyBoardUtils.OnSoftKeyBoardChangeListener() {
                @Override
                public void keyBoardShow(int height) {
                    layoutParams.height = height;
                    view.setLayoutParams(layoutParams);
                }

                @Override
                public void keyBoardHide(int height) {
                    layoutParams.height = 0;
                    view.setLayoutParams(layoutParams);
                }
            });
        }
        mBridgeWebSign.getSettings().setJavaScriptEnabled(true);
        mBridgeWebSign.getSettings().setAllowFileAccess(true);
        mBridgeWebSign.getSettings().setAllowFileAccessFromFileURLs(true);
        mBridgeWebSign.getSettings().setAllowUniversalAccessFromFileURLs(true);
        mBridgeWebSign.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        mBridgeWebSign.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        mBridgeWebSign.getSettings().setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
        mBridgeWebSign.getSettings().setLoadWithOverviewMode(true);//和setUseWideViewPort(true)一起解决网页自适应问题
        mBridgeWebSign.getSettings().setAppCacheEnabled(true);//是否使用缓存
        mBridgeWebSign.getSettings().setDomStorageEnabled(true);//DOM Storage
        mBridgeWebSign.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
        mBridgeWebSign.getSettings().setDatabaseEnabled(true);
        mBridgeWebSign.getSettings().setUseWideViewPort(true);
        mBridgeWebSign.getSettings().setTextZoom(100);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mBridgeWebSign.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        if (!CommonUtil.isBlank(mLoadUrl)) {
            mBridgeWebSign.loadUrl(TextUtils.isEmpty(mLoadUrl) ? "" : mLoadUrl);
        } else {
            mBridgeWebSign.loadData(TextUtils.isEmpty(mContent) ? "" : mContent, "text/html; charset=UTF-8", null);
        }
        mBridgeUtils = new BridgeWebViewUtils(mBridgeWebSign);
        mBridgeWebSign.setWebViewClient(new MyWebViewClient(mBridgeWebSign) {
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                mPbWebSignProgress.setVisibility(View.GONE);
                if (url.contains("rankingList") || url.contains("ActivityDescription")) {
                    tempUrl = url;
                } else {
                    tempUrl = "";
                }
                currentLoadUrl = url;
            }
        });

        mBridgeWebSign.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress == 100) {
                    if (mBridgeWebSign.getUrl() != null && mBridgeWebSign.getUrl().equals(mLoadUrl)) {
                        //同一个页面
                        mTvWebSignSend.setVisibility(isRightButton ? View.VISIBLE : View.GONE);
                    } else {
                        mTvWebSignSend.setVisibility(View.GONE);
                    }

                    mPbWebSignProgress.setVisibility(View.GONE);
//                    if (mLoadUrl.contains(BridgeConstant.ACTIVE_JINLIN_BUY) || mLoadUrl.contains("20210916")) {
//                        mBridgeUtils.sendJsData(BridgeConstant.GETTOKRN, "1", new CallBackFunction() {
//                            @Override
//                            public void onCallBack(String data) {
//                            }
//                        });
//                    }
                } else {
                    if (mPbWebSignProgress.getVisibility() == View.GONE)
                        mPbWebSignProgress.setVisibility(View.VISIBLE);
                    mPbWebSignProgress.setProgress(newProgress);
                }
                super.onProgressChanged(view, newProgress);
            }

            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
                //为解决6.0系统，这个api会调用两次，而且第一次是显示url的系统bug
                if (title != null && !view.getUrl().contains(title)) {
                    mTvWebSignTitle.setText(TextUtils.isEmpty(title) ? "" : (TextUtils.isEmpty(mLoadUrl) ? "" : title));
                }
            }

            @Override
            public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
                if (mUMA != null) {
                    mUMA.onReceiveValue(null);
                }
                mUMA = filePathCallback;
                Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                    File photoFile = null;
                    try {
                        photoFile = createImageFile();
                        takePictureIntent.putExtra("PhotoPath", mCM);
                    } catch (IOException ex) {
                    }
                    if (photoFile != null) {
                        mCM = "file:" + photoFile.getAbsolutePath();
                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                    } else {
                        takePictureIntent = null;
                    }
                }
                Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
//                contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
                contentSelectionIntent.setType("image/*");
                contentSelectionIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                Intent[] intentArray;
                if (takePictureIntent != null) {
                    intentArray = new Intent[]{takePictureIntent};
                } else {
                    intentArray = new Intent[0];
                }

                Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
                chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
                chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");

                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
                startActivityForResult(chooserIntent, FCR);
                return true;
            }
        });
        mIpJsDispatchCallBack = new IPJsDispatchCallBack(this, mBridgeWebSign) {
            @Override
            public void questionnaireBtn(CallBackFunction function, JSData.ParamBean mParam) {
                super.questionnaireBtn(function, mParam);
                if (mParam.getIsTrue() == 1) {
                    mTvWebSignSend.setBackgroundResource(R.drawable.rectf_14_f54d53);
                    mTvWebSignSend.setEnabled(true);
                } else {
                    mTvWebSignSend.setBackgroundResource(R.drawable.rectf_14_99999);
                    mTvWebSignSend.setEnabled(false);
                }
            }

            @Override
            public void jumpJinLinRushBuy(CallBackFunction function, JSData.ParamBean mParam) {
                super.jumpJinLinRushBuy(function, mParam);
            }
        };
        mBridgeUtils.registerHandler(mIpJsDispatchCallBack);
    }

    private File createImageFile() throws IOException {
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";
        File storageDir = Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES);
        File imageFile = File.createTempFile(
                imageFileName,  /* prefix */
                ".jpg",         /* suffix */
                storageDir      /* directory */
        );
        return imageFile;
    }

    private void initListener() {
        mIvWebSignBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                handleBack();
            }
        });
        mTvWebSignSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                JSData mJsData = new JSData();
                JSData.ParamBean mParamBean = new JSData.ParamBean();
                mParamBean.setFunc(100);
                mJsData.setParam(mParamBean);
                mBridgeUtils.sendJsData(BridgeConstant.GETTOKRN, GsonUtils.toJson(mJsData), new CallBackFunction() {
                    @Override
                    public void onCallBack(String data) {
                        IPJsDispatchCallBack.QUESTIONNAIRE_ID = Long.parseLong(data);//就先这样用吧
                        finish();
                    }
                });
            }
        });
    }

    private boolean isCanClose = false;
    private String tempUrl = "";
    //当前加载的url
    private String currentLoadUrl = "";

    private void handleBack() {
        if (mBridgeWebSign != null) {
            if (mBridgeWebSign.canGoBack()) {
                //
                if (!TextUtils.isEmpty(tempUrl)) {
                    mBridgeWebSign.loadUrl(BridgeConstant.H5_WHDS);
                    isCanClose = true;
                    return;
                }
                if (isCanClose) {
                    finish();
                } else {
                    if (currentLoadUrl.contains("homePage")) {
                        finish();
                        return;
                    }
                    mBridgeWebSign.goBack();
                }
            } else {
                if (isJumpMain) {
                    finish();
                } else {
                    finish();
                }
            }
        }
    }

    private void initView() {
        mRlWebSignTitle = findViewById(R.id.rl_web_sign_title);
        mIvWebSignBack = findViewById(R.id.iv_web_sign_back);
        mTvWebSignTitle = findViewById(R.id.tv_web_sign_title);
        mTvWebSignSend = findViewById(R.id.tv_web_sign_send);
        mPbWebSignProgress = findViewById(R.id.pb_web_sign_progress);
        mBridgeWebSign = findViewById(R.id.bridge_web_sign);
        spRefresh = findViewById(R.id.spring_refresh);
        mTvWebSignSend.setEnabled(false);
        spRefresh.setEnableLoadMore(false);
        spRefresh.setOnRefreshListener(refreshLayout -> {
            mBridgeWebSign.reload();
            spRefresh.finishRefresh();
        });
    }

    @Override
    public void getToken(CallBackFunction function) {

    }

    @Override
    public void getHaiBao(CallBackFunction function) {

    }

    @Override
    public void onBack(CallBackFunction function) {

    }

    @Override
    public void onDialog(CallBackFunction function, String content) {

    }

    @Override
    public void loadH5Token(String token, CallBackFunction function) {
        SpUtils.getInstance().putLoadDocumentToken(token);
    }

    @Override
    public void loadObject(Object data, CallBackFunction function) {

    }

    private class MyWebViewClient extends BridgeWebViewClient {
        MyWebViewClient(BridgeWebView webView) {
            super(webView);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            try {
                if (url.startsWith("weixin://") || url.startsWith("alipays://") || url.startsWith("tel://") || url.startsWith("baidu")) {
                    //类型我目前用到的是微信、支付宝、拨号 三种跳转方式，其他类型自加
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    startActivity(intent);
                    return true;
                }
                if (url.contains("&xxx=")) {//双十二领取成功关闭主题页
                    finish();
                }
            } catch (Exception e) {
                return false;
            }
            return super.shouldOverrideUrlLoading(view, url);
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);

        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
        }
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
//        if (data == null)
//            return;
        if (requestCode == IPJsDispatchCallBack.H5_APPOINT_MAP_RES) {
            switch (resultCode) {
                case IPJsDispatchCallBack.H5_APPOINT_MAP_RESULT:
                    mIpJsDispatchCallBack.sendJsAppointMap(data);
                    break;
                case 1001://添加选择地址
                    mIpJsDispatchCallBack.senJsNewAddress(data.getParcelableExtra("bean"));
                    break;
            }
        } else if (requestCode == Constants.KEY_NO_ADDRESS_ADD_ADDRESS && resultCode == 1001) {
            //新增地址
            if (data != null && data.hasExtra("bean")) {
                UserAddressData.DataBean bean = (UserAddressData.DataBean) data.getParcelableExtra("bean");

            }
        }
        if (Build.VERSION.SDK_INT >= 21) {
            Uri[] results = null;
            //Check if response is positive
            if (resultCode == Activity.RESULT_OK) {
                if (requestCode == FCR) {
                    if (null == mUMA) {
                        return;
                    }
                    if (data == null) {
                        //Capture Photo if no image available
                        if (mCM != null) {
                            results = new Uri[]{Uri.parse(mCM)};
                        }
                    } else {
                        String dataString = data.getDataString();
                        if (dataString != null) {
                            results = new Uri[]{Uri.parse(dataString)};
                        } else {
                            //多选
                            onActivityResultAboveL(data);
                            return;
                        }
                    }
                }
            }
            try {
                mUMA.onReceiveValue(results);
            } catch (Exception e) {
                e.printStackTrace();
            }
            mUMA = null;
        } else {
            if (requestCode == FCR) {
                if (null == mUM) return;
                Uri result = null;
                if (data == null) {
                    //Capture Photo if no image available
                    if (mCM != null) {
                        result = Uri.parse(mCM);
                    }
                } else {
                    result = data == null || resultCode != RESULT_OK ? null : data.getData();
                }
                try {
                    mUM.onReceiveValue(result);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                mUM = null;
            }
        }
    }

    //选中图片并传给js
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private void onActivityResultAboveL(Intent intent) {
        Uri[] results = null;
        if (intent != null) {
            String dataString = intent.getDataString();
            ClipData clipData = intent.getClipData();
            if (clipData != null) {
                results = new Uri[clipData.getItemCount()];
                for (int i = 0; i < clipData.getItemCount(); i++) {
                    ClipData.Item item = clipData.getItemAt(i);
                    results[i] = item.getUri();
                }
            }
            if (dataString != null) {
                results = new Uri[]{Uri.parse(dataString)};
            }
        }
        try {
            mUMA.onReceiveValue(results);
        } catch (Exception e) {
            e.printStackTrace();
        }
        mUMA = null;
    }

    //EventBus 接受方法
    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onEvent(final MessageBus messageBus) {
        if (messageBus.getCodeType().equals(MessageBus.msgId_active_receive_succ)) {
            mBridgeWebSign.reload();
        } else if (messageBus.getCodeType().equals(MessageBus.msgId_finish_h5_page)) {
            finish();
        } else if (messageBus.getCodeType().equals(MessageBus.msgId_show_share)) {
            if (!DoubleClickHelper.isOnDoubleClick()) {
                getShareInfo((int) messageBus.getParam1(), (int) messageBus.getParam2());
            }
        } else if (messageBus.getCodeType().equals(MessageBus.msgid_open_close_reule_pop)) {
            //与H5配合，解决滑动冲突（规则弹窗滑动 影响页面下拉刷新） 打开规则 禁止刷新，关闭规则 开启刷新
            Boolean isOpen = (Boolean) messageBus.getParam1();
            spRefresh.setEnableRefresh(!isOpen);
        } else if (messageBus.getCodeType().equals(MessageBus.msgId_finish_pay_mall)) {
            //关闭支付选择页 刷新
            mBridgeWebSign.reload();
        } else if (messageBus.getCodeType().equals(MessageBus.msgid_complate_task_one_refresh)) {
            // 完成任务一 通知h5 刷新
            mBridgeWebSign.reload();
        } else if (messageBus.getCodeType().equals(MessageBus.msgId_good_pay_succ)) {
            // 支付成功 通知h5 刷新
            mBridgeWebSign.reload();
        } else if (messageBus.getCodeType().equals(MessageBus.msgId_cancel_order_succ)) {
            // 订单取消支付 通知h5 刷新
            mBridgeWebSign.reload();
        } else if (messageBus.getCodeType().equals(MessageBus.msgId_select_search_wincellar)) {
            // 选择搜索的酒窖
            int id = (int) messageBus.getParam1();
            String name = (String) messageBus.getParam2();
            mIpJsDispatchCallBack.sendJsSearchWineCellar(id, name);
        } else if (messageBus.getCodeType().equals(MessageBus.msgid_web_back_page)) {
            handleBack();
        } else if (messageBus.getCodeType().equals(MessageBus.msgid_hide_top_title)) {
            mRlWebSignTitle.setVisibility(View.GONE);
        } else if (messageBus.getCodeType().equals(MessageBus.msgid_show_top_title)) {
            mRlWebSignTitle.setVisibility(View.VISIBLE);
        } else if (messageBus.getCodeType().equals(MessageBus.msgid_is_ban_back_page)) {
            //是否禁用侧滑返回 true：禁用，无法侧滑关闭当前页面
            isBanBackKey = true;
        } else if (messageBus.getCodeType().equals(MessageBus.msgid_h5_apply_camera_permission)) {
            //h5申请打开摄像头权限
            PermissionsUtils.getInstance().chekPermissions(this, PermissionCollection.CAMERA.permissionList, new PermissionsCall() {
                @Override
                public void permissionsPass() {
                }
            });
        } else if (messageBus.getCodeType().equals(MessageBus.msgid_h5_apply_status_bar_dark)) {
            StatusBarUtil.setStatusBarDarkTheme(this, true);
        } else if (messageBus.getCodeType().equals(MessageBus.msgId_new_add_address_success)) {
            //新增地址并传给H5
            ReceiveAddressBean addressBean = ((ReceiveAddressBean) messageBus.getMessage());
            mIpJsDispatchCallBack.senJsNewAddAddress(addressBean);
        } else if (messageBus.getCodeType().equals(MessageBus.msgId_select_address_complete)) {
            //选择地址并传给H5
            ReceiveAddressBean addressBean = ((ReceiveAddressBean) messageBus.getMessage());
            mIpJsDispatchCallBack.senJsNewAddAddress(addressBean);
        }
    }

    private void getShareInfo(int id, int luckId) {
        LoadingManager.showLoadingDialog(H5WebActivity.this);
        SendRequest.getShareInfo(SpUtils.getInstance().getLoadUserBean().getData().getId() + "", id + "", luckId + "", new GenericsCallback<ShareInfoDataBean>(new JsonGenericsSerializator()) {
            @Override
            public void onError(Call call, Exception e, int id) {
                LoadingManager.hideLoadingDialog(H5WebActivity.this);
            }

            @Override
            public void onResponse(ShareInfoDataBean response, int id) {
                LoadingManager.hideLoadingDialog(H5WebActivity.this);
                if (response == null || response.getData() == null) {
                    return;
                }
                PermissionsUtils.getInstance().chekPermissions(H5WebActivity.this,
                        PermissionCollection.FILE.permissionList, new PermissionsCall() {
                            @Override
                            public void permissionsPass() {
//                                new SharePopupWindow(H5WebActivity.this).setData(H5WebActivity.this, response, () -> {
//                                    LoadingManager.showLoadingDialog(H5WebActivity.this);
//                                    SharePosterBean sharePosterBean = new SharePosterBean(SharePosterActivity.SHARE_TYPE_TREND);
//                                    sharePosterBean.userAvatar = response.getData().getIcon();
//                                    sharePosterBean.userPhone = response.getData().getPhone();
//                                    sharePosterBean.isFans = response.getData().getIsFans() == 0;
//                                    sharePosterBean.shareContentBgUrl = response.getData().getHelpImg();
//                                    sharePosterBean.shareBgUrl = response.getData().getPosterImg();
//                                    sharePosterBean.shareImage = response.getData().getShareImg();
//                                    sharePosterBean.shareQrCodeUrl = response.getData().getShareUrl();
//                                    sharePosterBean.goodsList = response.getData().getCommodityList();
//                                    sharePosterBean.luckyConfigImg = response.getData().getLuckConfigImg();
//
//                                    ActivityPosterStyle posterStyle = new ActivityPosterStyle(H5WebActivity.this, sharePosterBean, path -> {
//                                        LoadingManager.hideLoadingDialog(H5WebActivity.this);
//                                        Bundle bundle = new Bundle();
//                                        bundle.putString(Constants.SHARE_POSTER_IMAGES, path);
//                                        bundle.putString(Constants.SHARE_POSTER_ACTIVITY_NAME, response.getData().getName());
//                                        bundle.putString(Constants.SHARE_POSTER_BAG_NAME, response.getData().getLuckConfigName());
//                                        ActivityRouter.startActivity(ActivityRouter.ACTIVITY.SHARE_POSTER_SHOW, bundle);
//                                    });
//                                    posterStyle.startDraw();
//                                }).showAtLocation(mBridgeWebSign, Gravity.BOTTOM, 0, 0);
                            }
                        });
            }
        });
    }


    @Override
    protected void onDestroy() {
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
        super.onDestroy();
        //清空所有cookie
        CookieSyncManager.createInstance(this);
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
        CookieSyncManager.getInstance().sync();
        mBridgeWebSign.setWebChromeClient(null);
        mBridgeWebSign.setWebViewClient(null);
        mBridgeWebSign.getSettings().setJavaScriptEnabled(false);
        mBridgeWebSign.clearCache(true);
        mBridgeWebSign.destroy();
    }

}
